<!--
 * @Author: 
 * @Date: 2021-12-29 21:52:08
 * @LastEditTime: 2022-01-06 10:29:17
 * @LastEditors: Please set LastEditors
 * @Description: 
 * @FilePath: \briup-webui-code\project_am\project_am-master\am-ui\src\pages\am\monitor\Monthly.vue

-->
<template>
  <div class="monthly">
    <div class="content">
      <div class="left">
        <el-input placeholder="输入关键字进行过滤" v-model="filterText">
        </el-input>
        <!-- 工程设备树 -->
        <el-tree
          :data="edTree"
          :props="props"
          @node-click="handleNodeClick"
          :filter-node-method="filterNode"
          ref="tree"
        ></el-tree>
      </div>
      <div class="right">
        <div class="block">
          <el-date-picker v-model="value" type="month" placeholder="选择月">
          </el-date-picker>

          <el-button type="primary" @click="toSearchHandler">查询</el-button>
        </div>

        <div v-show="mouthData.length == 0" class="notice">请选择设备查看</div>

        <div v-show="mouthData.length > 0">
          <el-table :data="mouthData" style="width: 100%">
            <el-table-column prop="d" label="日期"> </el-table-column>
            <el-table-column prop="tsp" label="tsp"> </el-table-column>
            <el-table-column prop="pm10" label="pm10"> </el-table-column>

            <el-table-column prop="pm25" label="pm25"> </el-table-column>

            <el-table-column prop="temperature" label="温度"> </el-table-column>

            <el-table-column prop="humidity" label="湿度"> </el-table-column>

            <el-table-column prop="wind_direction" label="风向">
            </el-table-column>
            <el-table-column prop="wind_speed" label="风速"> </el-table-column>
          </el-table>
        </div>

        <!-- 标签页 -->
      </div>
    </div>
  </div>
</template>
<script>
import { get } from "@/utils/request.js";
import moment from "moment";

export default {
  data() {
    return {
      value: "",

      edTree: [],
      props: {
        label: "name",
        value: "id",
      },
      params: {
        page: 1,
        pageSize: 50,
      },

      mouthData: [],

      filterText: "",
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },

  methods: {
    filterNode(value, edTree) {
      if (!value) return true;
      return edTree.name.indexOf(value) !== -1;
    },

    toSearchHandler() {
      this.queryMouthData();
    },

    // 树形节点点击事件
    handleNodeClick(data) {
      // 判断用户点击的是否是设备，点击工程时不查询数据
      if (data.engineer_id) {
        this.params = {
          ...this.params,
          engineer_id: data.engineer_id,
          device_id: data.id,
        };
        // 调用请求数据的方法
        /* this.queryMouthData();*/
      }
    },
    // 查询工程设备树
    findEngineerDeviceTree() {
      get("/engineer/findEngineerDeviceTree").then((res) => {
        this.edTree = res.data;
      });
    },

    queryMouthData() {
      get("/monitor/queryMouthData", this.params).then((res) => {
        this.mouthData = res.data;
      });
    },
  },

  created() {
    // 查询工程设备树
    this.findEngineerDeviceTree();
  },
};
</script>
<style scoped>
.content {
  display: flex;
}
.left {
  width: 30%;
  border-right: 1px solid #b9b7b7;
  padding-right: 20px;
  margin-right: 20px;
}
.right {
  width: 70%;
}
.notice {
  height: 500px;
  line-height: 500px;
  text-align: center;
  font-size: 30px;
  color: #999;
}
</style>